﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Transactions;
using A2DFramework.PipelineEngine;

namespace PETest
{
    class Program
    {
        static void Main(string[] args)
        {
            BO bo = new BO();

            Pipeline<string, bool> p = Pipeline.Wrap<string, bool>(bo.Add).Before(m => Console.WriteLine("before execute1"))
                                                                          .Before(m => Console.WriteLine("before execute2, transaction? ==>"+ (Transaction.Current==null? "null":Transaction.Current.TransactionInformation.LocalIdentifier)))
                                                                          .Next((m, n) => Console.WriteLine("after execute1"))
                                                                          .Next((m, n) => Console.WriteLine("after execute2"))
                                                                          .Successful((m, n) => Console.WriteLine("success"))
                                                                          .Exception((m, n) => Console.WriteLine("fail"))
                                                                          .Finally((m, n) => Console.WriteLine("final"));


            Console.WriteLine("Result: " + p.Invoke("testing").Result);

            Console.WriteLine();
            Console.WriteLine();

            p.EnableTransaction().DisableTransaction();

            Console.WriteLine("Result: " + p.Invoke(null).Result);

            Console.ReadKey();
        }
    }
}
